﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Text;
using System.Threading;
using System.Windows.Forms;

using Tao.Platform.Windows;
using VCMDL.NET;

namespace VoltGameEditor
{
	public delegate void PerspEventHandler(GlControl glc, EventArgs e);
	public delegate void ShadingEventHandler(Shading Type, GlControl glc, EventArgs e);

	public enum Shading
	{
		Wireframe,
		Solid,
		Textured
	}

	public interface IContextable
	{
		void MakeCurrentContext();
	}

	public class GlControl : SimpleOpenGlControl, IContextable
	{
		public NewCamera Cam;
		public int vpIndex;    //index of viewport so we can iterate correctly
		public int NumCameras; //total number of cameras for this viewport
		public bool is3d;
		public bool showGrid = true;
		public bool renderLighting = false;
		public bool renderFog = true;
		public MapObject SelectedObj = new MapObject();

		private Viewport.Perspectives _persp;
		private Shading _ShadeMode;
		public event PerspEventHandler PerspectiveChanged;
		public event ShadingEventHandler ShadingChanged;

		public Vector3 g_PanPosition;
		public Vector3 g_OldPanPosition;
		public Vector2 g_2dMouseVec;

		public Label ViewLabel = new Label();

		public void MakeCurrentContext()
		{
			MakeCurrent();
		}

		protected virtual void onPerspectiveChanged(GlControl glc, EventArgs e)
		{
			if (PerspectiveChanged != null)
				PerspectiveChanged(this, e);
		}
		protected virtual void onShadingChanged(Shading Type, GlControl glc, EventArgs e)
		{
			if (ShadingChanged != null)
				ShadingChanged(this.ShadeMode, this, e);
		}

		public Viewport.Perspectives Perspective
		{
			get { return _persp; }
			set
			{
				_persp = value;
				onPerspectiveChanged(this, EventArgs.Empty);
			}
		}

		public Shading ShadeMode
		{

			get { return _ShadeMode; }
			set
			{
				_ShadeMode = value;
				onShadingChanged(this._ShadeMode, this, EventArgs.Empty);
			}
		}

		public GlControl()
		{
			this.Size = new Size(372, 323);
			this.MouseEnter += new EventHandler(GlControl_MouseEnter);

			this.ViewLabel.Name = "tlbl_test";
			this.ViewLabel.Size = new Size(66, 17);
			this.ViewLabel.Font = new Font("Tomaha", 9, FontStyle.Regular);
			this.ViewLabel.Location = new Point(2, 2);
		}

		private void InitializeComponent()
		{
			this.SuspendLayout();
			// 
			// GlControl
			// 
			this.AllowDrop = true;
			this.AutoCheckErrors = true;
			this.AutoFinish = true;
			this.AutoValidate = System.Windows.Forms.AutoValidate.EnableAllowFocusChange;
			this.BackColor = System.Drawing.Color.Silver;
			this.Cursor = System.Windows.Forms.Cursors.Cross;
			this.ForeColor = System.Drawing.SystemColors.ControlText;
			this.Name = "GlControl";
			this.Size = new System.Drawing.Size(100, 100);
			this.Load += new System.EventHandler(this.GlControl_Load);
			this.ResumeLayout(false);

		}

		private void GlControl_MouseEnter(object sender, EventArgs e)
		{
			((GlControl)sender).MakeCurrent();
		}

		private void GlControl_Load(object sender, EventArgs e)
		{

		}
	}

	public class GLhandles
	{
		const float SingleDotSize = 2.3f;
	}

}
